<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/tree.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>数据权限配置</title>
<link href="${ctx}/styles/personal.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/personal.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script>
	var rightType="002";
	function openBuildingRight(thiz){
	    if(document.getElementById("td20").className=='quickMenu_toolbarico2')return false;
		var src="${ctx}/common_dataRightAction.do?method=getEmployeeRight&rightType=002&userId=${userId}";
		rightType="002";
		changeMenu(thiz,src);
	}
	function openPrecnctRight(thiz){
	     if(document.getElementById("td18").className=='quickMenu_toolbarico2')return false;
		var src="${ctx}/common_dataRightAction.do?method=getEmployeeRight&rightType=001&userId=${userId}";
		rightType="001";
		changeMenu(thiz,src);
	}
	function getCheckedItems(tree){
		var obj = findFrame('mainFrame');
		var t = obj.tree.getAllChecked();
		var result = "";
		if(rightType=="001"){
			result = treeParse(t,"precinct");
		}else{
			result = treeParse(t,"building");
		}
		if(result == "" && ${rightType}==-1){
			Alert("未选择任何节点");
			return false;
		}
		//if(result.split(",").length>1 && rightType=="001"){
		//	Alert("只能选择一个管理区!");
		//	return false;
		//}
		var url ="${ctx}/common_dataRightAction.do?method=editDataRight&userId=${userId}&idstr="+result+"&rightType="+rightType;
		var myrequest = new Ajax.Request(url,{method:"post",parameters:"",onComplete: showResponseDelete});
	}
	function showResponseDelete(response){
		if(response.responseText=="true"){
			SuccessAlert("分配成功");
			windowClose();
		}else{
			ajaxSubmitException(response.responseText);
		}
   }
	function treeParse(str,filter){
	    var s = "";
		var objs = str.split(",");
		for(var i = 0 ; i < objs.length;i++){
			if(objs[i].indexOf(filter) != -1){
				var index = objs[i].indexOf("_");
      			var id = objs[i].substr(index+1);
      			s = s+id+",";
			}
		}
		s =s.substring(0,s.length-1);
		return s;
	}
	function setRightType(rtype){
		rightType=rtype;
	}
	function treeReset(){
		var obj = findFrame('mainFrame');
		obj.tree.deleteChildItems(obj.tree.rootId);
		var t = obj.tree.loadXML("${ctx}/common_dataRightAction.do?method=getRightTreeData&rightType=${rightType}&userId=${userId}");
	}
	function init(){
		if(${rightType} == "001"){
			$('a20').className="tree_nav";
			$('a18').className="tree_nav_on";
			btn_Edit("td18","buildingImg","treefolder");
			btn_UnEdit("td20","precinctImg","ico_newfile2");
			rightType="001";
		}else if(${rightType} == "002"){
			btn_UnEdit("td18","buildingImg","ico_newfile2");
			btn_Edit("td20","precinctImg","treefolder");
			rightType="002";
		}

	}
</script>
</head>

<body onload="init()">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" align="absmiddle" /><span class="window_head_intext"> 数据权限配置</span></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>
    <td class="content"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">

      <tr>
        <td width="28%" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" id=topadcontent_10>
          <tr>
            <td valign="top">
              <table width="95%" border="0" cellspacing="0" cellpadding="0" id="tree_nav4">
				<tr>
                    <td>&nbsp;</td>
                </tr>
					<tr>
                  <td id="td20"><a href="#" onClick="openBuildingRight(this);return false" name="a20" class="tree_nav_on" onFocus="this.blur()"><img id="buildingImg" src="${ctx}/images/treefolder.gif" border="0"/> 按楼栋分配权限</a></td>
                </tr>
				<tr>
                    <td>&nbsp;</td>
                </tr>
                    <tr>
                  <td id="td18" ><a href="#" onClick="openPrecnctRight(this);return false" name="a18" class="tree_nav" onFocus="this.blur()"><img id="precinctImg" src="${ctx}/images/treefolder.gif" border="0" /> 按管理区分配权限</a></td>
                </tr>

                  </table></td>
          </tr>
        </table></td>
        <td width="70%" align="center" valign="top">
        <iframe src="${ctx}/common_dataRightAction.do?method=getEmployeeRight&rightType=${rightType}&userId=${userId}" name="mainFrame" id="mainFrame" title="dataRightTree" width="100%"  height="400px"  frameborder="0" border="0"   ></iframe></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="2" class="window_footer"><table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="buttonOffLeft" id="btn1_91"></td>
            <td class="buttonOffMiddle" id="btn1_92" onblur="btn_change(9)" onMouseOver="btn_change_over(9)" onMouseOut="btn_change_out(9)" onclick="treeReset();"><img src="${ctx}/images/ico_sx.gif" border="0" align="absmiddle" /> 重 置</td>
            <td class="buttonOffRight" id="btn1_93"></td>
          </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td ><table border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="buttonOffLeft" id="btn1_41"></td>
            <td class="buttonOffMiddle" id="btn1_42" onblur="btn_change(4)" onMouseOver="btn_change_over(4)" onMouseOut="btn_change_out(4)" onclick="getCheckedItems();"><img src="${ctx}/images/ico_ok.gif" border="0" align="absmiddle" /> 确 定</td>
            <td class="buttonOffRight" id="btn1_43"></td>
          </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" id="btn1_32" onClick="windowClose();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onBlur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom" />取 消</td>
              <td class="buttonOffRight" id="btn1_33"></td>
            </tr>
        </table></td>
      </tr>
    </table>
      <p>&nbsp;</p></td>
  </tr>
</table>
</body>
</html>